/******************************************************************************/
/*!
	\file	SoundSystem.h
	\author	Jack Kern
	\date	03/28/2007

	\brief
	
	This file is the main interface file for the HighLevel sound system
	it provides a complete interface for controling the larmobile sound engine.

	\par	license
	All content (c) 2005, DigiPen (USA) Corporation, all rights reserved.
*/
/******************************************************************************/
#pragma once

#include <Windows.h>
#include "Handles.h"

#undef PlaySound

// Predecl
namespace Audio
{
	class CoreSystem;
}


/******************************************************************************/
/*!
  \class SoundSystem
  \brief  
	The sound system class is the main controller class for the larmobile sound engine.
	This class ONLY includes the interface for the user.  All hidden work is done in
	the CoreSystem class.
*/
/*******************************************************************************/
class SoundSystem
{
public:
	SoundSystem() : m_core(0) {}

	bool Initialize( HWND hwnd, bool for_tool );						//!< Creates the low level engine
	bool Destroy();
	bool LoadSoundXML( const char* file, XMLFileHandle& handle );		//!< Set the sound XML file name that was created by the tool
	bool UnloadSoundXML( XMLFileHandle xmlFile );						//!< Unloads all sounds from a category not required by any other loaded category
	bool IsXMLLoaded( const char* file );								//!< Returns true if a specified category is currently loaded

	bool GetVarHandle( const char* varName, VariableHandle& handle, XMLFileHandle xmlFile );		//!< Returns a handle to a variable
	bool UpdateVariable( VariableHandle& handle, float value, XMLFileHandle xmlFile );				//!< Updates the value of a variable in the sound system
	bool TriggerEvent( const char* eventName, XMLFileHandle xmlFile );								//!< Triggers a sound event inside the sound system
	bool StopEvents();

public:
	void Update(float delta);											//!< Updates the sound system [ This must be called each frame ]

public:	// Direct access sound system functions
	bool		  LoadSoundFile( const WCHAR* file, FileHandle& handle );						//!< Load a sound file into memory and return the sound's handle
	bool		  LoadStreamFile( const WCHAR* file, FileHandle& handle  );											//!< Stream a sound file and return the sound's handle
	ChannelHandle PlayFile( const WCHAR* file, bool looping = false, float volume = 1.f );		//!< Directly streams and plays a sound by filename
	ChannelHandle PlayFile( FileHandle fileID, bool looping = false, float volume = 1.f );		//!< Plays a file loaded by sound file
	void		  UnloadSoundFile( FileHandle fileID );											//!< Unloads a loaded sound file by sound handle

	bool IsPlaying(const ChannelHandle& soundID);					//!< Returns true if a sound is currently playing
	void PlaySound(const ChannelHandle& soundID);					//!< Plays a single sound by sound handle.
	void SetVolume(const ChannelHandle& soundID, float volume);		//!< Sets the volume of a sound by sound handle.
	void StopSound(const ChannelHandle& soundID);					//!< Stops a specified sound by sound handle.

private:
	Audio::CoreSystem*	m_core;
};
